home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / oktime3d.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  4KB  |  119 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        oktime3d.c
  13.  * Purpose:     do a time-3D spectrum (meaning amplitude vs. freq. vs. time)
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     10-February-1994 CPP; Created.
  16.  *              29-August-1994 CPP (1.12); offset start time by 1/2 
  17.  *                interval to permit logarithmic displays.
  18.  *              7-Feb-95 CPP (1.31); Progress Requester
  19.  *
  20.  * Comment:     To preserve the full set of options available in a regular
  21.  *                ('flat') FFT, this function simply sets up and calls
  22.  *                ok_spectrum for each 'time segment.'
  23.  *              It 'forces' each segment by setting StartFrame and Frames
  24.  *                 as required.  Their original values are preserved
  25.  *                 here.
  26.  *              The real StartFrame (as specified by user) and Frames
  27.  *                 are to refer to the dataset as a whole,
  28.  *                 and NOT to each Time Segment.  Most other options
  29.  *                 (Overlap, Pad, Interleave, etc.) may still be applied
  30.  *                 to each individual time segment.
  31.  */
  32.  
  33. #include "gfft.h"
  34. #include "settings.h" /* Power, Amplitude, ReadPtr */
  35.  
  36. long Actual_Time_Segments = 1;  /* Used by progress indicator */
  37. extern long Inner_Loop_Count;
  38.  
  39. ULONG ok_time3d_spectrum (BOOLEAN do_it_for_real)
  40. {
  41.     ULONG save_ok_start_frame = OkStartFrame;
  42.     ULONG save_ok_frames = OkFrames;
  43.     ULONG dummy = 0;
  44.     ULONG frames;
  45.     ULONG running_offset;
  46.     ULONG bins_used = 0;
  47.     double segment_time_increment;
  48.     double fudge = 1.0 / LONG_MAX;  /* compensate for floating inaccuracy */
  49.     double time_overlap = TimeOverlap;
  50.     long time_seg_size = TimeSegSize;
  51.     long time_offset = TimeOffset;
  52.     long i;
  53.  
  54.     Actual_Time_Segments = TimeSegments;
  55.  
  56.     if (time_overlap == INVALID_SET ||
  57.     time_offset == INVALID_SET ||
  58.     Actual_Time_Segments == INVALID_SET ||
  59.     time_seg_size == INVALID_SET)
  60.     {
  61.     error_message (INVALID_TIMESEG_PARAMETERS);
  62.     RAISE_ERROR (NOTHING_SPECIAL);  /* longjmp outa here! */
  63.     }
  64.  
  65.     frames = (OkFrames != ULONG_MAX) ? OkFrames :
  66.       ok_read (NULL, dummy);
  67.  
  68.     if (time_seg_size == NOT_SET)
  69.     {
  70.     if (Actual_Time_Segments == NOT_SET)
  71.     {
  72.         error_message (MISSING_TIMESEG_PARAMETERS);
  73.         RAISE_ERROR (NOTHING_SPECIAL);  /* longjmp outa here! */
  74.     }
  75.     if (time_offset == NOT_SET)
  76.     {
  77.         time_seg_size = fudge + (frames / 
  78.           (1.0 + (1.0 - time_overlap) * (Actual_Time_Segments - 1)));
  79.         time_offset = fudge + (time_seg_size * (1.0 - time_overlap));
  80.     }
  81.     else
  82.     {
  83.         time_seg_size = frames - (time_offset * (Actual_Time_Segments - 1));
  84.     }
  85.     }
  86.     else
  87.     {
  88.     if (time_offset = NOT_SET)
  89.     {
  90.         time_offset = fudge + (time_seg_size * (1.0 - time_overlap));
  91.     }
  92.     Actual_Time_Segments = ((frames - time_seg_size) / time_offset) + 1;
  93.     }
  94. /*
  95.  * Now, we have the all dependent and independent parameters
  96.  */
  97.     segment_time_increment = time_seg_size / OkRate;
  98.     OkSegmentTime = segment_time_increment / 2;
  99.  
  100.     Inner_Loop_Count = 0;
  101.     running_offset = save_ok_start_frame;
  102.     for (i = 0; i < Actual_Time_Segments; i++)
  103.     {
  104.     OkStartFrame = running_offset;
  105.     OkFrames = time_seg_size;
  106.  
  107.     ok_rewind ();
  108.     bins_used = ok_spectrum (do_it_for_real);
  109.     if (!do_it_for_real) return bins_used;
  110.  
  111.     running_offset += time_offset;
  112.     OkSegmentTime += segment_time_increment;
  113.     }
  114.     OkStartFrame = save_ok_start_frame;
  115.     OkFrames = save_ok_frames;
  116.     Actual_Time_Segments = 1;
  117.     return bins_used;
  118. }
  119.